const express = require('express');
const router = express.Router();
const Payroll = require("../models/payroll")

router.get("/", async (req, res) => {
    try {
        const { currentPage, pageSize, searchMsg } = req.query
        const result = await Payroll.getPayroll(currentPage, pageSize, searchMsg)
        res.status(200).json({ code: 200, data: result.data, total: result.total })
    } catch (error) {
        res.status(500).json({ message: error.message })
    }
})

router.delete("/:id", async (req, res) => {
    try {
        const { id } = req.params
        const result = await Payroll.deletePayroll(id)
        if (result > 0) {
            res.status(200).json({ code: 200, message: "薪资记录删除成功" })
        } else {
            res.status(200).json({ code: 200, message: "薪资记录删除未找到" })
        }
    } catch (error) {
        res.status(500).json({ message: error.message })
    }
})

module.exports = router